﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using DataTransfer;
using EnglishLibrary;
using Global;

namespace EnglishReminder
{
    public partial class CategoryUC : UserControl
    {
        //object to access data
        private CategoryDT cateDT = new CategoryDT();

        #region Usercontrol Properties
        public string Text
        {
            get
            {
                return this.cbCategory.Text;
            }
        }

        public int SelectedIndex
        {
            get
            {
                return this.cbCategory.SelectedIndex;
            }
            set
            {
                this.cbCategory.SelectedIndex = value;
            }
        }
        #endregion

        public CategoryUC()
        {
            InitializeComponent();
        }

        private void CategoryUC_Resize(object sender, EventArgs e)
        {
            this.cbCategory.Size = new Size(this.Width, this.Height);
        }

        private void CategoryUC_Load(object sender, EventArgs e)
        {
            List<Category> cates = cateDT.GetListCategories();
            this.cbCategory.DataSource = cates;
            this.cbCategory.DisplayMember = Constant.CATEGORYFIELD.NAME;
            this.cbCategory.ValueMember = Constant.CATEGORYFIELD.CATEGORYID;
        }

        #region
        public int GetSelectedCateId()
        {
            if (this.cbCategory.SelectedValue != null)
                return Int32.Parse(this.cbCategory.SelectedValue.ToString());
            else
                return -1;
        }
        #endregion
    }
}
